package com.hsc.yalebao.http;

import android.content.Context;
import android.graphics.Bitmap;
import android.widget.ImageButton;

import com.hsc.yalebao.base.CustomApplication;
import com.hsc.yalebao.model.UserBaseBean;
import com.hsc.yalebao.tools.SharedPreferencesUtil;
import com.hsc.yalebao.tools.SystemHelper;
import com.hsc.yalebao.tools.UiUtil;
import com.hsc.yalebao.weight.LogUtils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.builder.GetBuilder;
import com.zhy.http.okhttp.builder.OkHttpRequestBuilder;
import com.zhy.http.okhttp.builder.PostFileBuilder;
import com.zhy.http.okhttp.builder.PostFormBuilder;
import com.zhy.http.okhttp.callback.BitmapCallback;
import com.zhy.http.okhttp.callback.FileCallBack;
import com.zhy.http.okhttp.callback.StringCallback;
import com.zhy.http.okhttp.request.RequestCall;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;
import okhttp3.OkHttpClient;


public class RequestNet {
    protected static final String TAG = "RequestNet";
    public static String accessToken = "";
    private static final OkHttpClient client = new OkHttpClient();
    private static int i;
    private static String memberId;
    private static String sessionToken;

    static {
        accessToken = CustomApplication.app.preferencesUtil.getValue(AppConstants.LOGIN_TOKEN, "");
        LogUtils.d("RequestNet", "accessToken:" + accessToken);
        i = 0;
    }

    public static void bindImageToView(String paramString, Context paramContext, ImageButton paramImageButton) {
        SystemHelper.isConnected(paramContext);
        OkHttpUtils.get().url(paramString).addHeader("accessToken", accessToken).tag(paramContext).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(new BitmapCallback() {
            public void onError(Call paramAnonymousCall, Exception paramAnonymousException) {
                UiUtil.showToast("访问失败");
            }

            public void onResponse(Bitmap paramAnonymousBitmap) {
                RequestNet.this.setImageBitmap(paramAnonymousBitmap);
            }
        });
    }

    public static void bindImageToView(String paramString, Context paramContext, BitmapCallback paramBitmapCallback) {
        SystemHelper.isConnected(paramContext);
        OkHttpUtils.get().url(paramString).addHeader("accessToken", accessToken).tag(paramContext).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(paramBitmapCallback);
    }

    public static void cancelTag(Object paramObject) {
        OkHttpUtils.getInstance().cancelTag(paramObject);
    }

    public static void downLoadFile(Context paramContext, String paramString, FileCallBack paramFileCallBack) {
        SystemHelper.isConnected(paramContext);
        OkHttpUtils.get().addHeader("accessToken", accessToken).url(paramString).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(paramFileCallBack);
    }

    public static void get(Context paramContext, String paramString, Map<String, String> paramMap, StringCallback paramStringCallback) {
        SystemHelper.isConnected(paramContext);
        HashMap localHashMap = new HashMap();
        if (CustomApplication.app.userBaseBean != null) {
            String str2 = CustomApplication.app.userBaseBean.memberid;
            String str3 = CustomApplication.app.userBaseBean.getSessionToken();
            accessToken = CustomApplication.app.userBaseBean.getAccessToken();
            LogUtils.i("RequestNet", "memberId:" + str2);
            LogUtils.i("RequestNet", "sessionToken:" + str3);
            localHashMap.put("accessToken", accessToken);
            localHashMap.put("Session-Token", str2 + "|" + str3);
            localHashMap.put("Authorization", "Bearer " + accessToken);
            if (!paramString.equals(AppConstants.WX_LOGIN))
                break label334;
            localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
        }
        while (true) {
            int j = 20000;
            if (paramString.equals(AppConstants.URL_GET_GETAPPVERISON))
                j = 5000;
            String str1 = AppConstants.BASE_URL + paramString;
            OkHttpUtils.get().headers(localHashMap).params(paramMap).url(str1).tag(paramContext).build().connTimeOut(j).execute(paramStringCallback);
            return;
            LogUtils.e("RequestNet", "CustomApplication.app.userBaseBean == null--get" + paramString);
            break;
            label334:
            if (paramString.equals(AppConstants.URL_GET_NEWWEXINLOGIN))
                localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
            else if (paramString.equals(AppConstants.URL_GET_OLDUSERLOGIN))
                localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
            else if (paramString.equals(AppConstants.URL_REGISTER))
                localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
            else if (paramString.equals(AppConstants.URL_GET_CONFIG))
                localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
            else if (paramString.equals(AppConstants.URL_GET_AD_LIST))
                localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
            else if (paramString.equals(AppConstants.URL_GET_FINDPASSWORD))
                localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
            else if (paramString.equals(AppConstants.URL_GET_VERYPASSWORD))
                localHashMap.put("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN);
        }
    }

    public static void multiFileUpload(Context paramContext, String paramString1, String paramString2, String paramString3, String paramString4, Map<String, String> paramMap, StringCallback paramStringCallback) {
        File localFile = new File(paramString2, paramString3);
        if (!localFile.exists()) {
            UiUtil.showToast("文件不存在，请修改文件路径");
            return;
        }
        OkHttpUtils.post().addFile(paramString4, paramString3, localFile).url(paramString1).addHeader("accessToken", accessToken).params(paramMap).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(paramStringCallback);
    }

    public static void post(Context paramContext, String paramString, Map<String, String> paramMap, StringCallback paramStringCallback) {
        SystemHelper.isConnected(paramContext);
        HashMap localHashMap = new HashMap();
        if (paramString.equals(AppConstants.URL_LOGIN)) {
            String str2 = AppConstants.BASE_URL + paramString;
            LogUtils.e("RequestNet", "url.equals(AppConstants.URL_LOGIN)---post");
            OkHttpUtils.post().addHeader("accessToken", accessToken).addHeader("Authorization", "Bearer " + AppConstants.NO_LOGIN_TOKEN).url(str2).tag(paramContext).params(paramMap).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(paramStringCallback);
            return;
        }
        if (CustomApplication.app.userBaseBean != null) {
            memberId = CustomApplication.app.userBaseBean.getMemberid();
            sessionToken = CustomApplication.app.userBaseBean.getSessionToken();
            accessToken = CustomApplication.app.userBaseBean.getAccessToken();
            LogUtils.i("RequestNet", "memberId:" + memberId);
            LogUtils.i("RequestNet", "sessionToken:" + sessionToken);
            localHashMap.put("accessToken", accessToken);
            localHashMap.put("Session-Token", memberId + "|" + sessionToken);
        }
        while (true) {
            String str1 = AppConstants.BASE_URL + paramString;
            OkHttpUtils.post().addHeader("Authorization", "Bearer " + accessToken).addHeader("accessToken", accessToken).addHeader("Session-Token", memberId + "|" + sessionToken).url(str1).tag(paramContext).params(paramMap).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(paramStringCallback);
            return;
            LogUtils.e("RequestNet", "CustomApplication.app.userBaseBean1 == null--post");
        }
    }

    public static void postFile(Context paramContext, String paramString, File paramFile, Map<String, String> paramMap, StringCallback paramStringCallback) {
        SystemHelper.isConnected(paramContext);
        OkHttpUtils.postFile().url(paramString).tag(paramContext).addHeader("accessToken", accessToken).file(paramFile).params(paramMap).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(paramStringCallback);
    }

    public static void postToken(Context paramContext, String paramString, Map<String, String> paramMap, StringCallback paramStringCallback) {
        String str1 = AppConstants.BASEIP + ":" + AppConstants.BASEPORT + paramString;
        String str2 = Base64Encoder.getInstance().encode("yalebao:yalebao123$");
        OkHttpUtils.post().addHeader("Authorization", "Basic " + str2).url(str1).tag(paramContext).params(paramMap).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(paramStringCallback);
    }

    public static void uploadFile(Context paramContext, String paramString1, String paramString2, String paramString3, StringCallback paramStringCallback) {
        File localFile = new File(paramString2, paramString3);
        if (!localFile.exists()) {
            UiUtil.showToast("文件不存在，请修改文件路径");
            return;
        }
        SystemHelper.isConnected(paramContext);
        OkHttpUtils.post().addFile("mFile", paramString3, localFile).url(paramString1).addHeader("accessToken", accessToken).build().connTimeOut(20000L).readTimeOut(20000L).writeTimeOut(20000L).execute(paramStringCallback);
    }
}

/* Location:           C:\Users\user\Desktop\dd28_pcdd720\classes_dex2jar.jar
 * Qualified Name:     com.hsc.yalebao.http.RequestNet
 * JD-Core Version:    0.6.2
 */